package cn.itrip.auth.service.impl;


import cn.itrip.auth.service.IItripUserService;
import cn.itrip.beans.dtos.Dto;
import cn.itrip.beans.dtos.ResultCodeEnum;
import cn.itrip.beans.pojo.ItripUser;
import cn.itrip.common.DtoUtil;
import cn.itrip.common.RedisAPI;
import cn.itrip.dao.ItripUserMapper;
import cn.itrip.trade.config.StateException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author 滕召伟
 * @since 2020-02-27
 */
@Service
public class ItripUserServiceImpl implements IItripUserService {
    @Resource
    private ItripUserMapper itripUserMapper;

    /**
     * 注册方法
     *
     * @param user
     * @return
     */
    @Override
    public void saveUser(ItripUser user) {
        try {
            itripUserMapper.saveUser(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 返回邮箱是否被注册
     *
     * @param userCode
     * @return userCode
     */
    @Override
    public Integer countCode(String userCode) {
        Integer count = itripUserMapper.countCode(userCode);
        return count;
    }

    /**
     * 激活邮箱
     *
     * @param userCode
     * @param activated
     */
    @Override
    public void updateActivated(String userCode, Integer activated) {
        try {
            itripUserMapper.updateActivated(userCode, activated);
        } catch (Exception e) {
            throw new StateException(ResultCodeEnum.PARAM_ERROR);
        }
    }

    /**
     * 用户登陆
     *
     * @param itripUser
     * @return
     */
    @Override
    public ItripUser findUserVoByUsernameAndPassword(ItripUser itripUser) {
        ItripUser user = itripUserMapper.findUserVoByUsernameAndPassword(itripUser);
        return user;
    }


}
